/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import DAO.DAO_Project;
import Entity.Project;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author THANHDAT
 */
@ManagedBean
@RequestScoped
public class ProjectBean {

    List<Project> lstPro = new ArrayList<Project>();
    Project project = new Project();
    int id;
    String name;
    private int category;
    private String shortDes;
    private String des;
    private String image;
    private String message;
    
    /** Creates a new instance of ProjectBean */
    public ProjectBean() {
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public List<Project> getLstPro() {
        return lstPro;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
        DAO_Project p = new DAO_Project();
        project = p.getProjectById(id);
    }

    public void setLstPro(List<Project> lstPro) {
        this.lstPro = lstPro;
    }
    
    public List<Project> showProject(){
        lstPro = DAO_Project.showProject();
        return lstPro;
    }
    public List<Project> showProjectById() throws SQLException{        
        DAO_Project pro = new DAO_Project();
        lstPro = pro.detail(id);
        return lstPro;
    }
    
    public void addProject(){
        try{            
            DAO_Project pro = new DAO_Project();
            pro.addProject(name, category, shortDes, des, image);
            setMessage("you add new data successfull!");
        }catch(Exception ex){
           ex.printStackTrace();
        }
    }

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    public String getShortDes() {
        return shortDes;
    }

    public void setShortDes(String shortDes) {
        this.shortDes = shortDes;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
